
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" type="text/css" href="ui/themes/default/easyui.css">
<link rel="stylesheet" type="text/css" href="ui/themes/icon.css">
<script type="text/javascript" src="ui/jquery.min.js"></script>
<script type="text/javascript" src="ui/jquery.easyui.min.js"></script>
<script type="text/javascript" src="ui/locale/easyui-lang-zh_CN.js"></script>
<script type="text/javascript" src="ui/jquery.serializejson.min.js"></script>

<script type="text/javascript">
	var method='';
	function edit(uuid){
		$("#editDlg").window('open');
		$("#editForm").form('clear');
		$("#editForm").form('load','dep_getDepById?id='+uuid);
		method="update";
	}
	
	function del(uuid){
		$.messager.confirm('提示', '您确认删除吗？', function(r){
			if (r){
			    $.ajax({
			    	url:'dep_delete?id='+uuid,
			    	type:'post',
			    	dataType:'json',
			    	success:function(res){
			    		$.messager.alert('提示',res.message,'info',function(){
			    			$("#deplist").datagrid('reload');
			    		});
			    	}
			    })
			}
		});


	}
	$(function(){
		$("#deplist").datagrid({
			url:"dep_list.action",
			columns:[[
			          {field:'uuid',title:'部门编号',width:100},
			          {field:'name',title:'部门名称',width:100},
			          {field:'tele',title:'部门电话',width:100},
			          {field:'-',title:'编辑',width:100,formatter: function(value,row,index){
			        	    var str='<a href="javascript:void(0);" onclick="edit('+row.uuid+')">修改</a>';
			        	    str+=' <a href="javascript:void(0);" onclick="del('+row.uuid+')">删除</a>';
							return str;
			        	  
						}}
			          ]],
			singleSelect:true,
			pagination:true,
			toolbar: [{
				iconCls: 'icon-add',
				text:'添加',
				handler: function(){
					method="add"
					$("#editForm").form('clear')
					$("#editDlg").window('open')
				}
			}]
		})
		
		$("#btnSearch").bind('click',function(){
			var jsonStr=$('#f1').serializeJSON();
			
			//alert(JSON.stringify(jsonStr));
			$('#deplist').datagrid('load',jsonStr);
		})
		
		$("#editDlg").dialog({
			title:'部门编辑',
			width:300,
			heigth:200,
			closed:true,
			modal:true
		})
		
		$("#btnSave").bind('click',function(){
			var jsonStr=$("#editForm").serializeJSON();
			$.ajax({
				url:'dep_'+method,
				data:jsonStr,
				type:'post',
				dataType:'json',
				success:function(res){
					if(res.success){
						$("#editDlg").window('close');
						$("#deplist").datagrid('reload');
					}
					$.messager.alert('提示',res.message);
				}
			})
		})
		
		
	});
	
</script>


<title>部门列表</title>
</head>
<body>
<form id="f1" method="post">   
    <div>   
        <label for="name">部门名称:</label>   
        <input class="easyui-validatebox" type="text" name="dep1.name" />   
    </div>   
    <div>   
        <label for="tele">部门电话:</label>   
        <input class="easyui-validatebox" type="text" name="dep1.tele"/>   
    </div>   
    <input type="button" value="查询" id="btnSearch">
</form>  
<table id="deplist"></table>
<div id="editDlg">
	<form id="editForm">
		<table>
			<tr>
				<td>部门名称</td>
				<td><input name="dep.name"><input type="hidden" name="dep.uuid" /></td>
			</tr>
			<tr>
				<td>部门电话</td>
				<td><input name="dep.tele"></td>
			</tr>
		</table>
		<button id="btnSave" type="button">保存</button>
	</form>
</div>


</body>
</html>